package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.mysql.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl  implements UserApi{

    @Autowired
    private UserMapper userMapper;

    //根据手机号码查询用户
    public User findByMobile(String mobile) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);
        return userMapper.selectOne(qw);
    }

    //保存用户，返回用户id
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    //根据环信id查询用户详情
    @Override
    public User findByHuanxin(String huanxinId) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getHxUser,huanxinId);
        return userMapper.selectOne(lqw);
    }

    //注册环信用户
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    //通过id查user
    @Override
    public User findById(Long valueOf) {
        User user = userMapper.selectById(valueOf);
        return user;
    }
}
